package com.km.team.phsystem.service.impl;

import com.km.team.phsystem.beans.pojo.SystemBusitype;
import com.km.team.phsystem.beans.pojo.SystemBusitypeExample;
import com.km.team.phsystem.beans.vo.SystemBusitypeVo;
import com.km.team.phsystem.dao.mybatis.SystemBusitypeMapper;
import com.km.team.phsystem.service.ISysBusiTypeService;
import com.km.team.phsystem.service.impl.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * Author: rochzhu
 * Date: 2018/11/26
 * Time: 19:00pm
 * Description: 业务类型
 */
@Service("iSysBusiTypeService")
public class SysBusiTypeServiceImpl extends BaseService<SysBusiTypeServiceImpl, SystemBusitype> implements ISysBusiTypeService {

    @Autowired
    private SystemBusitypeMapper systemBusitypeMapper;

    /**
     * 1.获取业务类型数据
     * @return
     * @throws Exception
     */
    @Override
    public List<SystemBusitype> getSysBusiTypeData() throws Exception {
        SystemBusitypeExample example =  new SystemBusitypeExample();
        return systemBusitypeMapper.selectByExample(example);
    }

    /**
     * 2.删除业务类型
     * @param id
     * @return
     * @throws Exception
     */
    @Transactional
    @Override
    public int delete(Integer id) throws Exception {
        return systemBusitypeMapper.deleteByPrimaryKey(id);
    }

    /**
     * 3.通过业务类型名称去重
     * @param busiTypeVo
     * @return
     * @throws Exception
     */
    @Override
    public List<SystemBusitype> getSystemBusiType(SystemBusitypeVo busiTypeVo) throws Exception {
        SystemBusitypeExample example = new SystemBusitypeExample();
        SystemBusitypeExample.Criteria criteria = example.createCriteria();
        criteria.andBusitypeEqualTo(busiTypeVo.getBusitype());
        return  systemBusitypeMapper.selectByExample(example);
    }

    /**
     * 4.通过ID获取业务类型
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public SystemBusitype getSystemBusiTypeByID(int id) throws Exception {
        return systemBusitypeMapper.selectByPrimaryKey(id);
    }

    /**
     * 5.添加业务类型
     * @param busiTypeVo
     * @return
     * @throws Exception
     */
    @Transactional
    @Override
    public int add(SystemBusitypeVo busiTypeVo) throws Exception {
        SystemBusitype conf = new SystemBusitype();
        conf.setId(0);
        conf.setBusitype(busiTypeVo.getBusitype());
        conf.setBusitypeCount(busiTypeVo.getBusitype_count());
        conf.setNote(busiTypeVo.getNote());
        return systemBusitypeMapper.insert(conf);
    }

    /**
     * 6.更新业务类型
     * @param systemBusitype
     * @return
     * @throws Exception
     */
    @Transactional
    @Override
    public int updateBusiType(SystemBusitype systemBusitype) throws Exception {
        return systemBusitypeMapper.updateByPrimaryKeySelective(systemBusitype);
    }


}
